from django import forms
from web import models
from web.forms.bootstrap import BootStripForm

class WikiModelForm(BootStripForm,forms.ModelForm):
    class Meta:
        model = models.Wiki
        # fields = ['title','content','parent']
        exclude = ['project','depth']
    # 选择当前用户的parent，而不是全部的parent
    def __init__(self,request, *args, **kwargs):
        super().__init__(*args, **kwargs)
        # 从数据库中获取当前项目所有的wiki标题
        total_data_list=[('','请选择'),]
        data_list=models.Wiki.objects.filter(project=request.tracer.project).values_list('id','title')
        total_data_list.extend(data_list)
        self.fields['parent'].choices = total_data_list

